package kr.or.javacafe.board.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.SqlMapClientTemplate;

import kr.or.javacafe.board.domain.*;

import org.springframework.stereotype.Repository;

@Repository
public class BoardDAOImpl implements BoardDAO {
	private static final String NAMESPACE = "board.";

	@Autowired
	private SqlMapClientTemplate sqlMapClientTemplate;

	public SqlMapClientTemplate getSqlMapClientTemplate() {
		return sqlMapClientTemplate;
	}

	
	
	
	@Override
	public ArticleFile selectDownloadFile(ArticleFile articleFile) {
		return (ArticleFile)getSqlMapClientTemplate().queryForObject(NAMESPACE + "selectDownloadFile", articleFile);
	}
	
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Comment> selectCommentList(Comment comment) {
		return getSqlMapClientTemplate().queryForList(NAMESPACE + "selectCommentList", comment);
	}
	
	
	@Override
	public void insertComment(Comment comment) {
		getSqlMapClientTemplate().insert(NAMESPACE + "insertComment", comment);
	}
	
	
	@Override
	public void deleteComment(Comment comment) {
		getSqlMapClientTemplate().insert(NAMESPACE + "deleteComment", comment);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Article> selectPreviewNoticeArticle() {
		return getSqlMapClientTemplate().queryForList(NAMESPACE + "selectPreviewNoticeArticle");
	}
	
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Article> selectPriviewRecentArticle() {
		return getSqlMapClientTemplate().queryForList(NAMESPACE + "selectPriviewRecentArticle");
	}

	
	@Override
	public int selectArticleNoSeq() {
		getSqlMapClientTemplate().insert(NAMESPACE + "updateArticleNoSeq");		
		return (Integer)getSqlMapClientTemplate().queryForObject(NAMESPACE + "selectArticleNoSeq");
	}

	@Override
	public int selectBbsThreadNo(String bbsId) {
		return (Integer)getSqlMapClientTemplate().queryForObject(NAMESPACE + "selectBbsThreadNo", bbsId);
	}
	
	@Override
	public void insertArticle(Article article) {
		getSqlMapClientTemplate().insert(NAMESPACE + "insertArticle", article);
	}
	
	@Override
	public void insertArticleFile(ArticleFile file) {
		getSqlMapClientTemplate().insert(NAMESPACE + "insertArticleFile", file);
	}
	
	
	@Override
	public Bbs selectBbs(Bbs bbs) {
		return (Bbs)getSqlMapClientTemplate().queryForObject(NAMESPACE + "selectBbs", bbs);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Article> selectArticleList(Article article) {
		return getSqlMapClientTemplate().queryForList(NAMESPACE + "selectArticleList", article);
	}
	
	@Override
	public int selectArticleListCount(Article article) {
		return (Integer)getSqlMapClientTemplate().queryForObject(NAMESPACE + "selectArticleListCount", article);
	}
	
	@Override
	public Article selectArticle(int atcNo) {
		return (Article)getSqlMapClientTemplate().queryForObject(NAMESPACE + "selectArticle", atcNo);
	}
	
	
	@Override
	public void updateArticle(Article article) {
		getSqlMapClientTemplate().insert(NAMESPACE + "updateArticle", article);
	}

	
	@Override
	public void deleteArticle(Article article) {
		getSqlMapClientTemplate().insert(NAMESPACE + "deleteArticle", article);
	}

	
	@Override
	public void deleteArticleFile(ArticleFile file) {
		getSqlMapClientTemplate().delete(NAMESPACE + "deleteArticleFile", file);
	}
	
	@Override
	public void updateReplyArticle(Article article) {
		getSqlMapClientTemplate().delete(NAMESPACE + "updateReplyArticle", article);
	}


}





